﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class BulletMotion : ScriptableObject
{
    [Tooltip("生命周期")]
    public float lifeTime;
    [Tooltip("被唤醒的时间")]
    public float awakeTime;
    [HideInInspector]
    public BulletMotionController motionController;

    protected bool awake;

    protected Vector2 TowardsDir
    {
        set
        {
            motionController.towards = value;
        }
        get
        {
            return motionController.towards;
        }
    }



    protected virtual void Start()
    {
        awake = true;
    }

    protected virtual void End()
    {
        awake = false;
        motionController.RemoveMotion(this);
        DestroyImmediate(this, true);
    }

    public virtual void Awaking(float t)
    {
        if (t > awakeTime)
        {
            if (!awake)
            {
                Start();
            }
        }
    }

    public virtual Vector2 Motion(float t)
    {
        return Vector2.zero;
    }

    public virtual void Ending(float t)
    {
        if (t > lifeTime + awakeTime)
        {
            if (awake)
            {
                End();
            }
        }
    }
}
